package spring.cloud.tasks.executor.executor.task.execute_runtime_context;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

public class TaskExecuteRuntimeContext {

    public ConcurrentHashMap<String, TaskInstanceExecuteRuntimeContext> taskInstanceIdToTaskInstanceExecuteRuntimeContextMap = new ConcurrentHashMap<String, TaskInstanceExecuteRuntimeContext>();

    /**
     * 一定会有值得，一般任务不会超过1024.后期会增加一个定时任务对过期的实例进行清理
     */
    public TaskInstanceExecuteRuntimeContext getTaskInstanceExecuteRuntimeContext(String taskInstanceId) {
        taskInstanceIdToTaskInstanceExecuteRuntimeContextMap.put(taskInstanceId, new TaskInstanceExecuteRuntimeContext());
        TaskInstanceExecuteRuntimeContext taskInstanceExecuteRuntimeContext = taskInstanceIdToTaskInstanceExecuteRuntimeContextMap.get(taskInstanceId);
        return taskInstanceExecuteRuntimeContext;
    }

    public List<TaskItemExecuteRuntimeContext> needReRenewalAtNextExecutePeriodTaskItemExecuteRuntimeContextList = new CopyOnWriteArrayList<>();
}
